﻿using login.model;
using login1.bll;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp6
{
    public partial class MainForm : Form
    {
        private LoginInfoBll x=new LoginInfoBll();
        //private LoginInfoDal y;
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            label1.Text = Tag.ToString();
            LoadData();
        }

        private void LoadData()
        {
            dataGridView1.DataSource = x.GetPeople();
            //dataGridView1.DataSource=
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            people p=x.GetPeople().FirstOrDefault();
            string str = p.username;
            MessageBox.Show($"{str+"\t"+p.password}");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if(x.Add())
            {
                LoadData();
                MessageBox.Show("成功");
                
            }
            else
            {
                MessageBox.Show("失败");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if(x.UpdateByid("LLL"))
            {
                LoadData();
                MessageBox.Show("成功");
            }
            else
            {
                MessageBox.Show("失败！");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if(x.DeleteByid())
            {
                LoadData();
                MessageBox.Show("成功");
            }
            else
            {
                MessageBox.Show("失败");
            }
        }
    }
}
